package com.clouddot.baipai.presenter;


import com.clouddot.baipai.contract.IAttendFragmentContract;
import com.clouddot.baipai.http.entity.response.getClassRecordResponse;
import com.clouddot.baipai.http.entity.response.getRecordByIdResponse;

import org.wxy.sdk.base.impl.BasePresenterImpl;

import java.util.ArrayList;

import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;

public class AttendFragmentPresenter extends BasePresenterImpl<IAttendFragmentContract.IView, IAttendFragmentContract.IModel> implements IAttendFragmentContract.IPresenter {
    public AttendFragmentPresenter(IAttendFragmentContract.IView view, IAttendFragmentContract.IModel model) {
        super(view, model);
    }


    @Override
    public void getClassAttendRecord(String classId) {
        Subscription subscription = mModel.getClassAttendRecord("QueryClassCardCount", classId)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<ArrayList<getClassRecordResponse>>() {
                               @Override
                               public void call(ArrayList<getClassRecordResponse> responses) {
                                   mView.success(1, responses);
                               }
                           }
                        , new Action1<Throwable>() {
                            @Override
                            public void call(Throwable throwable) {
                                mView.fail(1, throwable.getMessage());

                            }
                        });
        addSubscription(subscription);
    }

    @Override
    public void getStudentAttendRecord(int pageindex, int pagesize) {
        Subscription subscription = mModel.getStudentAttendRecord("QueryForCardRecordPage", pageindex, pagesize)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<getRecordByIdResponse>() {
                               @Override
                               public void call(getRecordByIdResponse response) {
                                   mView.success(2, response);
                               }
                           }
                        , new Action1<Throwable>() {
                            @Override
                            public void call(Throwable throwable) {
                                mView.fail(2, throwable.getMessage());

                            }
                        });
        addSubscription(subscription);
    }
}
